<!-- 物资申领 -->
<template>
	<view>
		<bg-tab :tabs="tabs" :current="current" @tab-change="tabChange"></bg-tab>
		<view class="p-3">
			<view v-if="dataList.length>0">
				<u-list @scrolltolower="loadMore" style="height:calc(100vh - 260rpx)">
					<view v-for="i,idx in dataList" :key="idx" class="bt-block py24px30 mb-3" @tap="gotoDetail(i)">
						<view class="flex justify-between">
							<view>
								<bg-desc label="申领物资" :value="i.materialName"></bg-desc>
								<bg-desc label="申领人" :value="i.createUserName"></bg-desc>
								<bg-desc label="申领时间" :value="i.createTime"></bg-desc>
							</view>
							<view>
								<u--image v-if="i.status==1" src="/static/images/ui/salary/wait.png" width="154rpx" height="154rpx"></u--image>
								<u--image v-if="i.status==2" src="/static/images/ui/salary/pass.png" width="154rpx" height="154rpx"></u--image>
								<u--image v-if="i.status==3" src="/static/images/ui/salary/reject.png" width="154rpx" height="154rpx"></u--image>
							</view>
						</view>
					</view>
				</u-list>
					
			</view>
			<u-empty v-else></u-empty>
			
		</view>
	</view>
</template>

<script>
	import { getApplyList, getManagerList } from '@/api/apply'
	export default {
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url:"/pages/more/apply/apply"
			})
		},
		onLoad(options) {
			this.getData()
			uni.$on('apply-refresh', ()=>{
				this.dataList = []
				this.params.pageNum = 1
				this.getData()
			})
		},
		data() {
			return {
				role:'',
				params:{
					status:1,
					pageNum:1,
					pageSize:20,
				},
				current:0,
				tabs:['待审批', '审批通过', '审批未通过'],
				dataList:[],
				total:0,
			}
		},
		methods: {
			tabChange(e){
				this.current = e
				this.params.status = e+1
				this.dataList = []
				this.params.pageNum = 1
				this.getData()
			},
			getData(){
				let method = getApplyList
				if(this.$auth.hasRoleOr(['project'])){
					method = getManagerList
				}
				method(this.params).then(res=>{
					this.dataList=[...this.dataList, ...res.data.rows]
					this.total = res.data.total
				})
			},
			loadMore(){
				if(this.dataList.length<this.total){
					this.params.pageNum += 1
					this.getData()
				}
			},
			gotoDetail(i){
				uni.navigateTo({
					url:"/pages/more/apply/detail?id="+i.id
				})
			}
		}
	}
</script>

<style>

</style>
